from datetime import datetime

from pydantic import BaseModel

from schemas.common import Paging


class UserCreate(BaseModel):
    username: str
    nickname: str
    password: str
    phone_number: str
    email: str
    roles: list[int]

    class Config:
        from_attributes = True


class UserUpdate(BaseModel):
    id: int
    username: str
    nickname: str
    phone_number: str
    email: str
    roles: list[int]

    class Config:
        from_attributes = True


class UserResponse(BaseModel):
    id: int
    username: str
    nickname: str
    phone_number: str
    email: str
    roles: list["RoleResponse"]
    created_at: datetime

    class Config:
        from_attributes = True


class UsersResponse(BaseModel):
    data: list[UserResponse] = []
    paging: "Paging"

    class Config:
        from_attributes = True


class RoleCreate(BaseModel):
    name: str
    description: str
    permissions: list[int]

    class Config:
        from_attributes = True


class RoleResponse(BaseModel):
    id: int
    name: str
    description: str
    created_at: datetime
    permissions: list["PermissionResponse"]

    class Config:
        from_attributes = True

class RolesResponse(BaseModel):
    data: list[RoleResponse] = []
    paging: "Paging"


class RoleUpdate(BaseModel):
    id: int
    name: str
    description: str
    permissions: list[int]

    class Config:
        from_attributes = True


class PermissionCreate(BaseModel):
    name: str
    description: str
    father_id: int

class PermissionUpdate(BaseModel):
    id: int
    name: str
    description: str
    father_id: int

class PermissionResponse(BaseModel):
    id: int
    name: str
    description: str
    father_id: int
    created_at: datetime


class PermissionsResponse(BaseModel):
    data: list[PermissionResponse] = []
    paging: "Paging"

class RolesPermissionsResponse(BaseModel):
    role: RoleResponse
    permissions: list[PermissionResponse]
